﻿#pragma once
namespace LK
{
	namespace Drawing
	{
		/**@brief 表示一个矩形，T表示坐标数据的类型*/
		template<class T>class Rect
		{
		public:
			/**@brief 起点坐标（对应屏幕坐标左上角）*/
			Point<T> point;
			/**@brief 保存大小*/
			Size<T> size;
			/**@brief 默认构造*/
			Rect(){}
#ifdef _WINDOWS
			/**@brief 从Windows的方框构造*/
			Rect(::RECT const&rect) :point(rect.left, rect.top), size(rect.right - rect.left, rect.bottom - rect.top){}
			operator ::RECT()const{ ::RECT rect; rect.left = point.x; rect.top = point.y; rect.right = point.x + size.width; rect.bottom = point.y + size.height; return rect; }
#endif
			/**@brief 由坐标和大小构造*/
			Rect(T const& x1, T const&y1, T const&w, T const&h) :point(x1, y1), size(w, h){}
			/**@brief 由两个坐标构造*/
			Rect(Point<T> const& pStart, Point<T> const& pEnd) :point(pStart), size(pEnd.x - pStart.x, pEnd.y - pStart.y){}
			/**@brief 由起始坐标和大小构造*/
			Rect(Point<T> const& pStart, Size<T> const& size) :point(pStart), size(size){}
			/**@brief 坐标正偏移*/
			inline friend Rect operator+(const Rect & p1, const Point<T> & p2){ return Rect(p1.point + p2, p1.size); }
			inline Rect & operator+=(const Point<T> & p){ return *this = *this + p; }
			inline Rect operator+()const{ return *this; }
			/**@brief 坐标负偏移*/
			inline friend Rect operator-(const Rect & p1, const Point<T> & p2){ return Rect(p1.point - p2, p1.size); }
			Rect & operator-=(const Point<T> & p){ return *this = *this - p; }
			inline Rect operator-()const{ return Rect(-point-size, size); }
			/**@brief 坐标乘*/
			inline friend Rect operator*(const Rect & p, const T & i){ return Rect(p.point*i, p.size*i); }
			Rect & operator*=(const T & i){ return *this = *this * i; }
			/**@brief 坐标除*/
			inline friend Rect operator/(const Rect & p, const T & i){ return Rect(p.point / i, p.size / i); }
			Rect & operator/=(const T & i){ return *this = *this / i; }
			/**@brief 比较*/
			bool operator==(Rect const& l)const{ return l.point == point&&size == l.size; }
			bool operator!=(Rect const& l)const{ return l.point != point || size != l.size; }
			/**@brief 获取中点坐标*/
			Point<T> GetPointCenter()const{ return Point<T>(point.x + size.width / 2, point.y + size.height / 2); }
		};

	}
}
